package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文件名:");
        String name = sc.nextLine();
        FileOutputStream fos = new FileOutputStream(name+".txt");
        OutputStreamWriter  osw=new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        /*
        true表示打开自动行刷新,每当调用println方法后自动flush
         */
        PrintWriter pw = new PrintWriter(bw,true);

        while (true){
            System.out.println("请输入内容或输入exit退出");
            while (true){
                String tr = sc.nextLine();
                if(tr.equals("exit")){
                    System.out.println("退出成功");
                    return;
                }
                    pw.println(tr);

                }



        }
    }
}
